// Save this script as `options.js`

// Saves options to localStorage.
function save_options() {
  var numberX = document.getElementById("x");
  var x = numberX.value;
  localStorage["x"] = x;
  var numberY = document.getElementById("y");
  var y = numberY.value;
  localStorage["y"] = y;
  var width = document.getElementById("w");
  var w = width.value;
  localStorage["w"] = w;
  var height = document.getElementById("h");
  var h = height.value;
  localStorage["h"] = h;
  // Update status to let user know options were saved.
  var status = document.getElementById("status");
  status.innerHTML = "Options Saved.";
  setTimeout(function() {
    status.innerHTML = "";
  }, 750);
}

// Restores option state from localStorage.
function restore_options() {
  var numberX = document.getElementById("x");
  numberX.value = localStorage["x"];
  var numberY = document.getElementById("y");
  numberY.value = localStorage["y"];
  var width = document.getElementById("w");
  width.value = localStorage["w"];
  var height = document.getElementById("h");
  height.value = localStorage["h"];
}

document.addEventListener('DOMContentLoaded', restore_options);
document.querySelector('#save').addEventListener('click', save_options);
